package com.ewanghuiju.app.widget.popupwindow;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.ewanghuiju.app.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import razerdp.basepopup.BasePopupWindow;

/**
 * @author sj  qq:751943509
 * @class 公共的弹框
 * @time 2020/2/19
 */
public class CustomBasePopup extends BasePopupWindow {


    @BindView(R.id.tv_popup_title)
    TextView tvPopupTitle;
    @BindView(R.id.tv_giveup)
    TextView tvGiveup;
    @BindView(R.id.tv_gopay)
    TextView tvGopay;
    @BindView(R.id.tv_popup_content)
    TextView tvPopupContent;

    private PopupWindowCallback popupWindowCallback;

    public CustomBasePopup(Context context, String title, String sureText, String cancel, PopupWindowCallback popupWindowCallback) {
        super(context);
        ButterKnife.bind(this, getContentView());
        tvPopupTitle.setText(TextUtils.isEmpty(title) ? "" : title);
        tvGiveup.setText(TextUtils.isEmpty(cancel) ? "\u3000取消\u3000" : cancel);
        tvGopay.setText(TextUtils.isEmpty(sureText) ? "\u3000确认\u3000" : sureText);
        this.popupWindowCallback = popupWindowCallback;
    }

    /**
     * 设置title
     *
     * @param title
     */
    public void setTitleText(String title) {
        if (tvPopupTitle != null) {
            tvPopupTitle.setText(title);
        }
    }

    /**
     * 设置内容文本
     * @param contentText
     */
    public void setContentText(String contentText) {
        if (tvPopupContent != null) {
            tvPopupContent.setVisibility(View.VISIBLE);
            tvPopupContent.setText(contentText);
        }
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.popup_pintuan_giveup_pay);
    }

    @OnClick({R.id.tv_giveup, R.id.tv_gopay})
    public void doClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.tv_giveup:
                dismiss();
                if (popupWindowCallback != null) {
                    popupWindowCallback.cancelClickCallback();
                }
                break;
            case R.id.tv_gopay:
                //确定按钮
                dismiss();
                if (popupWindowCallback != null) {
                    popupWindowCallback.sureClickCallback();
                }
                break;
            default:
                break;
        }
    }

    public interface PopupWindowCallback {

        void sureClickCallback();

        void cancelClickCallback();
    }
}
